/**
 *  编辑页
 *
 * 作者 admin
 * 日期 2024-08-20 15:49:12
 */
layui.use(['jquery','febs', 'form', 'validate','fileUpload'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        commonJS = layui.commonJS,
        fileUpload = layui.fileUpload,
        $view = $('#hazardExamineDetail-edit'),
        $hazardOperation = $view.find('#hazardOperation'),
        tableIns,
        validate = layui.validate;
    let auditRecordList=[];

    initDictItemLabel_rectify();
    form.verify(validate);
    form.render();

    initFormValue();

    if(hazardExamineDetailData){
        if(hazardExamineDetailData.examineFileList && hazardExamineDetailData.examineFileList.length>0){
            var imgViewBoxRecord = fileUpload.render({
                elem: '#imgViewBoxRecord',
                url: '',
                type: 0,//0-图片，1-视频，2-其他
                maxNum:5,
                defaultData: hazardExamineDetailData.examineFileList,
                isDetail: true,
                done: function (res) {
                },
            });
        }
        if(hazardExamineDetailData.rectifyFileList && hazardExamineDetailData.rectifyFileList.length>0){
            var imgViewBoxRectify = fileUpload.render({
                elem: '#imgViewBoxRectify',
                url: '',
                type: 0,//0-图片，1-视频，2-其他
                maxNum:5,
                defaultData: hazardExamineDetailData.rectifyFileList,
                isDetail: true,
                done: function (res) {
                },
            });
        }
    }

    function initDictItemLabel_rectify(){
        febs.initDictItemLabel($hazardOperation,'SAFETY_ACCIDENT_TYPE',hazardExamineDetailData.hazardOperation);
    }

    initRecordAuditTable();
    function initRecordAuditTable() {
        tableIns = febs.table.init({
            elem: $view.find("#recordAuditTable"),
            id: 'recordAuditTable',
            page:false,
            skin: '',
            limit:Number.MAX_VALUE,
            cols: [[
                {title: '序号', type: 'numbers',width: 60},
                {field: 'auditRealName', title: '审核人姓名', width: 150},
                {field: 'auditResult',align:'center', title: '审核结果', width: 100, templet: function (d) {
                        return d.auditResult =='1'?'审核通过':'审核退回';
                    }
                },
                {field: 'auditReason', title: '审核理由', minWidth: 260},
                {field: 'createdTime',align:'center', title: '审核时间', width: 180},
            ]],
            done: function(res, curr, count){
            },
            data:auditRecordList
        });
    }

    function initFormValue() {
        if (hazardExamineDetailData) {
            if(hazardExamineDetailData.auditRecordList && hazardExamineDetailData.auditRecordList.length>0){
                auditRecordList = hazardExamineDetailData.auditRecordList;
            }
            form.val("hazardExamineDetail-edit-form", {
                "examineRecordId": hazardExamineDetailData.examineRecordId,
                "tenantId": hazardExamineDetailData.tenantId,
                "examineId": hazardExamineDetailData.examineId,
                "hazardExamineTitle": hazardExamineDetailData.hazardExamineTitle,
                "hazardOperation": hazardExamineDetailData.hazardOperation,
                "hazardLevel": hazardExamineDetailData.hazardLevel,
                "areaId": hazardExamineDetailData.areaId,
                "areaName": hazardExamineDetailData.areaName,
                "examineEvidence": hazardExamineDetailData.examineEvidence,
                "projectId": hazardExamineDetailData.projectId,
                "projectName": hazardExamineDetailData.projectName,
                "leaderDeptId": hazardExamineDetailData.leaderDeptId,
                "leaderDeptName": hazardExamineDetailData.leaderDeptName,
                "leaderId": hazardExamineDetailData.leaderId,
                "leaderName": hazardExamineDetailData.leaderName,
                "leaderNo": hazardExamineDetailData.leaderNo,
                "questionDescription": hazardExamineDetailData.questionDescription,
                "rectificationDeadline": hazardExamineDetailData.rectificationDeadline,
                "rectificationRequire": hazardExamineDetailData.rectificationRequire,
                "feedbackContent": hazardExamineDetailData.feedbackContent,
                "feedbackDate": hazardExamineDetailData.feedbackDate,
                "auditUserId": hazardExamineDetailData.auditUserId,
                "auditRealName": hazardExamineDetailData.auditRealName,
                "auditRemark": hazardExamineDetailData.auditRemark,
                "auditDate": hazardExamineDetailData.auditDate,
                "status": hazardExamineDetailData.status,
                "recordUserId": hazardExamineDetailData.recordUserId,
                "recordRealName": hazardExamineDetailData.recordRealName,
                "recordDate": hazardExamineDetailData.recordDate,
                "auditRecordList": hazardExamineDetailData.auditRecordList,
            });
            form.render('checkbox');
        }
    }

});